package com.work.demo.threaddemo;

import com.work.demo.entity.User;
import com.work.demo.utils.UserUtils;

/**
 * @ProjectName: demo
 * @Package: com.example.demo.threaddemo
 * @ClassName: DaemonThread
 * @Author: Deng YuBin
 * @Description: 控制线程2-后台线程，又称守护线程，JVM的垃圾回收线程就是典型的后台线程
 * 后台线程的最大特征是： 如果所有的前台线程都死亡，后台线程会自动死亡
 * @Date: 2020/10/14 22:41
 * @Version: 1.0
 */
public class DaemonThread extends Thread {

	public void run() {
		System.out.println(UserUtils.get());
	}

	public static void main(String[] args) {


		User user1 = new User();
		user1.setName("wang1");
		UserUtils.set(user1);
		System.out.println(Thread.currentThread().getId());

		User user = new User();
		user.setName("wang");
		UserUtils.set(user);
		System.out.println(Thread.currentThread().getId());



		DaemonThread t = new DaemonThread();
		System.out.println(t.getId());
		//启动后台线程
		t.start();

	}


}
